package com.example.guiguihomemedical.controller;

import com.example.guiguihomemedical.common.Result;
import com.example.guiguihomemedical.entity.Fulfillment;
import com.example.guiguihomemedical.entity.dto.FamilyarChivesList;
import com.example.guiguihomemedical.entity.dto.FamilyarChivesRecordList;
import com.example.guiguihomemedical.entity.dto.FamilyarSigning;
import com.example.guiguihomemedical.entity.dto.RecordAdd;
import com.example.guiguihomemedical.service.FamilyarChivesService;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import java.lang.reflect.Type;
import java.util.List;

@RestController
@RequestMapping("FamilyarChives")
public class FamilyarChivesController {
    @Autowired
    private FamilyarChivesService familyarChivesService;
    @GetMapping("/idcard/{idcard}")
    public Result getFamilyarChivesList(@PathVariable String idcard){
        FamilyarChivesList familyarChivesList = familyarChivesService.findByIdCardAllFamilyList(idcard);
        return Result.success(familyarChivesList);
    }
    @GetMapping("/signingList")
    public Result getFamilyarChivesSigningList(@RequestParam(required = false, value = "IdCard") String IdCard,@RequestParam(required = false, value = "doctorId") int doctorId){
        FamilyarSigning familyarSigning = familyarChivesService.familySigningInformation(IdCard,doctorId);
        return Result.success(familyarSigning);
    }
    @PostMapping("/idcardList")
    public Result getFamilyarChivesList(MultipartHttpServletRequest request){
        String idcardList = request.getParameter("idcardList");
        Gson gson = new Gson();
        Type listType = new TypeToken<List<String>>(){}.getType();
        List<String> FamilyIdcardList = gson.fromJson(idcardList, listType);
        List<FamilyarChivesRecordList> familyarChivesRecordLists = familyarChivesService.findByIdCardAllListNo(FamilyIdcardList);
        return Result.success(familyarChivesRecordLists);
    }
    @PostMapping("/idcardListBy")
    public Result getByFamilyarChivesList(MultipartHttpServletRequest request){
        String idcardList = request.getParameter("idcardList");
        String idNamePhone = request.getParameter("idNamePhone");
        Gson gson = new Gson();
        Type listType = new TypeToken<List<String>>(){}.getType();
        List<String> FamilyIdcardList = gson.fromJson(idcardList, listType);
        List<FamilyarChivesRecordList> familyarChivesRecordLists = familyarChivesService.findByIdCardAllListNo(FamilyIdcardList,idNamePhone);
        return Result.success(familyarChivesRecordLists);
    }
    @PostMapping("/addMember")
    public Result addFamilyarChivesMember(@RequestParam(required = false, value = "householdId") String householdId,@RequestParam(required = false, value = "memberId") String memberId){
        familyarChivesService.insertFamilyarchives(householdId,memberId);
        return Result.success("添加成功！");
    }
    @DeleteMapping("/delete")
    public Result deleteFamilyarchives(@RequestParam(required = false, value = "IdCard") String IdCard){
        familyarChivesService.deleteFamilyarchives(IdCard);
        return Result.success("删除成功！");
    }
    @PostMapping("/add")
    public Result addFamilyarChives(@RequestParam(required = false, value = "IdCard") String IdCard){
        familyarChivesService.addFamilyarchives(IdCard);
        return Result.success("创建成功！");
    }
    @PutMapping("/UpDate")
    public Result updateFamilyarChives(@RequestParam(required = false, value = "IdCard") String IdCard,@RequestParam(required = false, value = "relationship") String relationship){
        familyarChivesService.updateFamilyarchives(IdCard,relationship);
        return Result.success("修改成功！");
    }
}
